<?php
namespace App\Http\Controllers\Reception;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\admin\Netsetting;
use App\admin\Scrollimg;
use App\admin\Logo;
use App\admin\Category;
use App\admin\Good;

class ProductController extends Controller
{
	public function __construct() {
//		$this->middleware('admindo');
	}
	
	public function index()
	{
		//取网站设置
		$net = new Netsetting;
		$Netsettings = $net::find(1);
		//取滚动图片
		$scrolls = Scrollimg::get();
		//几个LOGO
		$Logos = Logo::get();
		
		//案例分类
		$Category = Category::get();
		$getId = $Category[0]['id'];
		if($getId == ""){
			return "没有此数据";
		}
		$data = Good::where('type',$getId)->get();
		
		if(empty($data)){
			return "没有此数据";
		}else{
			return view('reception.product',['type'=>$Category,'data' => $data,'logo'=>$Logos,'setData'=>$Netsettings,'scrollData'=>$scrolls]);
		}
		
	}
	
	//通过ajax取得某一分类
	public function getIndex(Request $request){
		
		$type = $request->input('type');
		if($type == ""){
			return '{"state":"0","msg":"分类出错"}';
		}
		
		$data = Good::where('type',$type)->get();
		$json = json_encode($data);
		if($json != '' && strlen($json)>2){
			return '{"state":"2","data":'.$json.'}';;
		}
		return '{"state":"1","msg":"没有返回"}';
	}
	
	public function ProductSee(Request $request){
		//取网站设置
		$net = new Netsetting;
		$Netsettings = $net::find(1);
		//取滚动图片
		$scrolls = Scrollimg::get();
		//几个LOGO
		$Logos = Logo::get();
		
		$id = $request->input('id');
		$Anli = new Good;
		$data = $Anli::find($id);
		
//		dd($data);
		
		$Category = Category::get();
		
		if(empty($data)){
			return "没有此数据";
		}else{
			return view('reception.productsee',['type'=>$Category,'data' => $data,'logo'=>$Logos,'setData'=>$Netsettings,'scrollData'=>$scrolls]);
		}
	}
	
}
